import requests

class Webrequests:
    def __init__(self,url, para, headers):
        self.url =url
        self.para =para
        self.headers = headers

    def get(self):
        try:
            r = requests.get(url=self.url, params=self.para, headers=self.headers)
            print("获取返回的状态码", r.status_code)
            json_r = r.json()
            print("json类型转化成python数据类型",json_r)
        except BaseException as e:
            print("请求失败！",str(e))

    def post(self):
        try:
            print(self.headers)
            r = requests.post(url=self.url, params=self.para, headers=self.headers, verify=False)
            print("获取返回的状态码", r.status_code)
            json_r = r.json()
            print("json类型转化成python数据类型", json_r)
            return r
        except BaseException as e:
            print("请求失败！", str(e))




    def post_json(self):
        try:
            data = self.para
            data = json.dumps(data)   #python数据类型转化为json数据类型
            r = requests.post(self.url, data=data, header=self.headers)
            print("获取返回的状态码",r.status_code)
            json_r = r.json()
            print("json类型转化成python数据类型",json_r)
        except BaseException as e:
            print("请求失败！",str(e))

